package ru.megazlo.basemvc.dao.dto;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.AbstractPersistable;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.List;

@Entity
@Table(name = "News")
@EntityListeners({AuditingEntityListener.class})
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
public class News extends AbstractPersistable<Long> {

	@CreatedDate
	private LocalDateTime createdDate;
	@LastModifiedDate
	private LocalDateTime lastModifyDate;
	@Column(length = 400, nullable = false)
	private String title;
	private String fullText;
	private String shortText;
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "autorId", nullable = false)
	private User autor;
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "editorId", nullable = false)
	private User lastEdit;
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "news")
	private List<Comment> comments;

	public LocalDateTime getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(LocalDateTime createdDate) {
		this.createdDate = createdDate;
	}

	public LocalDateTime getLastModifyDate() {
		return lastModifyDate;
	}

	public void setLastModifyDate(LocalDateTime lastModifyDate) {
		this.lastModifyDate = lastModifyDate;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getFullText() {
		return fullText;
	}

	public void setFullText(String fullText) {
		this.fullText = fullText;
	}

	public String getShortText() {
		return shortText;
	}

	public void setShortText(String shortText) {
		this.shortText = shortText;
	}

	public User getAutor() {
		return autor;
	}

	public void setAutor(User autor) {
		this.autor = autor;
	}

	public User getLastEdit() {
		return lastEdit;
	}

	public void setLastEdit(User lastEdit) {
		this.lastEdit = lastEdit;
	}

	public List<Comment> getComments() {
		return comments;
	}

	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}
}
